package com.vipboot.framework.mybatisplus.datapermission.autoconfig;

import com.vipboot.framework.core.spring.SpringContextUtil;
import com.vipboot.framework.mybatisplus.autoconfig.MybatisPlusAutoConfig;
import com.vipboot.framework.mybatisplus.datapermission.core.DataPermissionAspect;
import com.vipboot.framework.mybatisplus.datapermission.core.PlusDataPermissionInterceptor;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(MybatisPlusAutoConfig.class)
public class MybatisPlusDataPermissionAutoConfig {
    @PostConstruct
    public void postConstruct() {
        log.info("初始化 MybatisPlusDataPermissionAutoConfig");
    }

    /**
     * 数据权限拦截器
     */
    @Bean
    public PlusDataPermissionInterceptor dataPermissionInterceptor() {
        return new PlusDataPermissionInterceptor(SpringContextUtil.getProperty("mybatis-plus.mapperPackage"));
    }

    /**
     * 数据权限切面处理器
     */
    @Bean
    public DataPermissionAspect dataPermissionAspect() {
        return new DataPermissionAspect();
    }
}
